#include "Nod.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
char *ftoa(long double x)
{
    char buffer[1000], *rez;

    ftoa(x, buffer, 10);
    rez = new char[strlen(buffer) + 1];
    rez[0] = '\0';
    strcpy(rez, buffer);

    return rez;
}

void ftoa(long double aux, char *buffer, int nrzec)
{   int i, j, auxint, sgn = 1;
    long double aux2;

    if (aux < 0)
    {
        aux *= -1;
        aux2 = floorl(aux);
        sgn = -1;
    }
    else aux2 = floorl(aux);

    ITOA(aux2 + 1e-100, buffer);
    if (sgn == -1)
    {
        for (i = strlen(buffer) + 1; i > 0; i--)
            buffer[i] = buffer[i - 1];
        buffer[0] = '-';
    }

    aux -= aux2;
    i = strlen(buffer);

    if (!(ISZERO(aux)) && nrzec > 0) buffer[i++] = '.';
    while (nrzec > 0 && !(ISZERO(aux)))
    {
        aux *= 10;
        buffer[i++] = floorl(aux) + '0';
        aux -= floorl(aux);
        nrzec--;
    }
    buffer[i] = '\0';
}

void ITOA(int x, char *buffer)
{
    int i = 0, sgn = 0;

    if (!x)
    {
        buffer[i++] = '0'; buffer[i++] = '\0'; return;
    }
    if (x < 0)
    {
        sgn = 1;
        x *= -1;
    }

    while (x)
    {
        buffer[i++] = x % 10 + '0';
        x /= 10;
    }

    if (sgn) buffer[i++] = '-';
    buffer[i] = '\0';

}
char *cpystr(char *string1)
{
    char *rez;
    if (!string1)
        return string1;

    rez = new char[strlen(string1) + 1];
    strcpy(rez, string1);

    return rez;
}
Nod::Nod(void)
{
    fStang = NULL;
    fDrept = NULL;
}

Nod::~Nod()
{
    if (fStang) delete fStang;
    if (fDrept) delete fDrept;
}

long double Nod::x = 0;

void Nod::setX(long double X)
{
    x = X;
}

long double Nod::getX()
{
    return x;
}

Nod *Nod::getFStang()
{
    return fStang;
}

void Nod::setFStang(Nod *x)
{
    fStang = x;
}

Nod *Nod::getFDrept()
{
    return fDrept;
}

void Nod::setFDrept(Nod *x)
{
    fDrept = x;
}

